home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / dsiic2.zip / L_WIN3.C < prev    next >
C/C++ Source or Header  |  1991-07-15  |  9KB  |  313 lines

  1. /* Copyright (c) James L. Pinson 1990,1991  */
  2.  
  3. /**********************   L_WIN3.C   ***************************/
  4.  
  5. #include "mydef.h"
  6. #include <dos.h>
  7.  
  8. #if defined QUICKC
  9.  
  10. #include "malloc.h"
  11. #include "memory.h"
  12.  
  13. #endif
  14.  
  15. #if defined TURBOC
  16.  
  17. #include "alloc.h"    /* Turbo C header file */
  18. #include "mem.h"
  19. #include "string.h"
  20. #include "stdlib.h"
  21.  
  22. #endif
  23.  
  24.  
  25. /*****************************************************************
  26.  
  27.  Usage: void win_ceol(int handle, int x, int y);
  28.  
  29.  handle= Window handle.
  30.  x= column.
  31.  y= row.
  32.  
  33.  Clears the window indicated by handle from the x-y coordinate to
  34.  the end of the line.
  35.  
  36. *****************************************************************/
  37.  
  38. void win_ceol(int handle, int x, int y)
  39. {
  40. extern struct screen_structure scr;
  41. extern struct window_structure w[];
  42.  
  43.  
  44.   if(w[handle].buffer==NULL){  /* if it is the top window call ceol() */
  45.     ceol(x,y);
  46.     return;
  47.    }
  48.  
  49.   win_point(handle);  /* direct output to handle */
  50.    ceol(x,y);         /* now we can call ceol()  */
  51.   win_point(handle);  /* a second call to win_point() redirects
  52.                          output to original values.
  53.                          note: the parameter "handle" is ignored */
  54. }
  55.  
  56.  
  57. /*****************************************************************
  58.  
  59.  Usage: void win_cls(int handle);
  60.  
  61.  handle= Window handle.
  62.  
  63.  Clears the screen of the window indicated.
  64.  
  65. *****************************************************************/
  66.  
  67. void win_cls(int handle)
  68. {
  69. extern struct screen_structure scr;
  70. extern struct window_structure w[];
  71.  
  72.   /* if it is the top window call cls() */
  73.   if(w[handle].buffer==NULL){  
  74.     cls();
  75.     return;
  76.    }
  77.  
  78.   win_point(handle);/* direct output to handle */
  79.    cls();           /* output is redirected, we can call cls() now */
  80.   win_point(handle);/* a second call to win_point() redirects
  81.                        output to original values. */
  82. }
  83.  
  84.  
  85. /*****************************************************************
  86.  
  87.  Usage: void win_scroll_up(int handle, int lines);
  88.  
  89.  handle= Window handle.
  90.  
  91.  Scrolls the window indicated by "handle" up by the number
  92.  indicated by "lines".
  93.  
  94. *****************************************************************/
  95.  
  96. void win_scroll_up(int handle,int lines)
  97. {
  98. extern struct screen_structure scr;
  99. extern struct window_structure w[];
  100.  
  101.   if(w[handle].buffer==NULL){  /* if the window is not virtual */
  102.    scroll_up(lines);           /* call scroll_up(); */
  103.    return;
  104.    }
  105.  
  106.   win_point(handle);    /* redirect output to handle */
  107.    scroll_up(lines);    /* now scroll_up */
  108.   win_point(handle);    /* toggle output back to previous value */
  109. }
  110.  
  111.  
  112. /*****************************************************************
  113.  
  114.  Usage: void win_scroll_down(int handle, int lines);
  115.  
  116.  handle= Window handle.
  117.  
  118.  Scrolls the window indicated by "handle" down by the number
  119.  indicated by "lines".
  120.  
  121. *****************************************************************/
  122.  
  123. void win_scroll_down(int handle,int lines)
  124. {
  125. extern struct screen_structure scr;
  126. extern struct window_structure w[];
  127.  
  128.   if(w[handle].buffer==NULL){  /* if the window is not virtual */
  129.    scroll_down(lines);         /* call scroll_down(); */
  130.    return;
  131.    }
  132.  
  133.   win_point(handle);   /* redirect output to handle */
  134.    scroll_down(lines); /* now scroll_down */
  135.   win_point(handle);   /* toggle output back to previous value */
  136. }
  137.  
  138.  
  139. /*****************************************************************
  140.  
  141.  Usage: void win_goxy(int handle, int x,int y);
  142.  
  143.  handle= Window handle.
  144.  x,y   = column and row.
  145.  
  146.  Moves the cursor to the position x,y relative to window (handle).
  147.  The cursor is visible only in the current active window.
  148.  If the window (handle) is not active, the change is not seen
  149.  until the window is made active (moved to the top).
  150.  
  151. *****************************************************************/
  152.  
  153. void win_goxy(int handle,int x,int y)
  154. {
  155. extern struct screen_structure scr;
  156. extern struct window_structure w[];
  157.  
  158.   if(w[handle].buffer==NULL){  /* if the window is not virtual */
  159.    goxy(x,y);                /* call scroll_up(); */
  160.    return;
  161.    }
  162.  
  163.   win_point(handle);    /* redirect output to handle */
  164.     goxy(x,y);          /* move the cursor */
  165.   win_point(handle);    /* toggle output back to previous value */
  166.  
  167. }
  168.  
  169.  
  170. /*****************************************************************
  171.  
  172.  Usage: void win_print(int handle, int x, int y, char *string);
  173.  
  174.  handle= Window handle.
  175.  x,y= Position (column and row).
  176.  string= String to write.
  177.  
  178.  Writes string in window indicated by handle.
  179.  
  180. *****************************************************************/
  181.  
  182. void win_print( int handle, int x,int y, char *string)
  183. {
  184. extern struct screen_structure scr;
  185. extern struct window_structure w[];
  186.  
  187.   if(w[handle].buffer==NULL){   /* if not virtual */
  188.    print(x,y,string);           /* call print routine */
  189.    return;
  190.    }
  191.    win_point(handle);   /* direct output to window */
  192.     print(x,y,string);  /* call print routine */
  193.    win_point(handle);   /* toggle pointer back to original values */
  194. }
  195.  
  196.  
  197. /*****************************************************************
  198.  
  199.  Usage: static win_point(int handle);
  200.  
  201.  handle= Window handle.
  202.  
  203.  This function is used internally by many of the win_ functions.
  204.  
  205.  It saves important values stored in the screen(scr) and window
  206.  (w) data structures and replaces them with new values which point
  207.  to the window indicated.  It in essence "tricks" other routines
  208.  into acting on the new window.  A second call to win_point()
  209.  acts as a toggle and restores the original values.
  210.  
  211. *****************************************************************/
  212.  
  213. static void win_point(int handle)
  214. {
  215. extern struct screen_structure scr;
  216. extern struct window_structure w[];
  217.  
  218. static char far *hold_screen;
  219. static int t,b,l,r;
  220.  
  221. /*
  222.   We are going to trick the external definitions of the screen
  223.   (scr.buffer, scr.rows, scr.columns, scr.top, scr.bottom, scr.left,
  224.   and scr.right) so they "point" to the virtual window.  If the
  225.   window is framed, the margins will show an indention of 1, if
  226.   unframed then no indention. */
  227.  
  228. /* the following variables are used to store the "true"
  229.    external variables */
  230.  
  231. static int wt,wb,wl,wr;
  232. static int rows,columns;
  233. static int in_use=FALSE;
  234. static int update;
  235. static int active;
  236. static int snow;
  237.  
  238. if (w[handle].buffer==NULL) return;  /* return if window is active */
  239.  
  240.   if(in_use==FALSE){   /* enter here if the function is not already
  241.                           pointing to another window? */
  242.  
  243.     in_use=TRUE;       /* mark it used */
  244.     update=scr.update; /* store old update info */
  245.  
  246.     scr.update=FALSE;  /* don't update cursor, window is virtual */
  247.  
  248.     hold_screen=scr.buffer;  /* save screen buffer */
  249.     snow =scr.snow;          /* save snow info */
  250.     scr.snow= FALSE;  /* window is virtual, we are not writting to
  251.                          screen so we don't need to worry about
  252.                          snow */
  253.  
  254.     active=scr.active;  /* save old active */
  255.     scr.active=handle;  /* set handle as new active window */
  256.  
  257.  
  258.     t=scr.top,b=scr.bottom,  /* save more values */
  259.     l=scr.left,r=scr.right;
  260.  
  261.     /* store the old row, columns setting */
  262.     rows=scr.rows;columns=scr.columns; 
  263.  
  264.     /* the following are the margin values of the window.
  265.        save them, and use for calculations of new margins */
  266.  
  267.     wt=w[handle].top;
  268.     wb=w[handle].bottom;
  269.     wl=w[handle].left;
  270.     wr=w[handle].right;
  271.  
  272.     /* now make the pointer to the screen buffer
  273.        point to our window buffer */
  274.     scr.buffer=(char far *) w[handle].buffer;
  275.  
  276. /* now find out if the window has a frame and
  277.    set the window margins accordingly */
  278.  
  279.     if(w[handle].frame==FALSE){  /* no frame */
  280.      scr.rows=wb-wt+1;           /* set screen rows and columns */
  281.      scr.columns=wr-wl+1;        /* to values of window */
  282.  
  283.      scr.top=1;             /* set margin values */
  284.      scr.bottom=scr.rows;
  285.      scr.left=1;
  286.      scr.right=scr.columns;
  287.     } else                  /* the window has a frame */
  288.     {
  289.       scr.rows=wb-wt+3;  /* include frame in rows and column count */
  290.       scr.columns=wr-wl+3;
  291.  
  292.       scr.top=2;            /* set margins so frame not included */
  293.       scr.bottom=scr.rows-1;
  294.       scr.left=2;
  295.       scr.right=scr.columns-1;
  296.     }
  297.  
  298.   } else             /* active =TRUE */
  299.   {                  /* enter here to restore original values */
  300.    in_use=FALSE;
  301.    scr.update=update;   /* restore update flag */
  302.  
  303.    /* restore values */
  304.  
  305.    scr.top=t; scr.bottom=b;
  306.    scr.left=l;scr.right=r;
  307.    scr.rows=rows; scr.columns=columns;
  308.    scr.buffer=hold_screen;
  309.    scr.active=active;
  310.    scr.snow=snow;
  311.   }
  312. }
  313.